//
//  WYAllClueController.m
//  CirclePush
//
//  Created by admin on 2018/4/19.
//  Copyright © 2018年 admin. All rights reserved.
//

#import "WYAllClueController.h"
#import "WYClueCell.h"
#import "WYClewModel.h"
@interface WYAllClueController ()<UITableViewDelegate,UITableViewDataSource>
@property (nonatomic,strong)UITableView *tableView;
@property (nonatomic,strong)NSMutableArray *dataArray;
@end

@implementation WYAllClueController
-(NSMutableArray *)dataArray
{
    if (!_dataArray) {
        _dataArray = [[NSMutableArray alloc]init];
    }
    
    return _dataArray;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    [self setupUI];
    [self loadData];
}
-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    
    
    
}
-(void)setupUI
{
    [self.view addSubview:self.tableView];
    [self.tableView registerNib:[UINib nibWithNibName:@"WYClueCell" bundle:nil] forCellReuseIdentifier:@"WYClueCell"];
    self.tableView.backgroundColor = [UIColor hexStringToColor:@"#f0f0f0" alpha:0];
    self.view.backgroundColor = [UIColor hexStringToColor:@"#f4f4f4" alpha:1.0];
    self.tableView.tableFooterView = [[UIView alloc]init];
}


-(void)loadData
{
//    if ([self.type isEqualToString:@""]) {
//
//    }
//    if ([self.type isEqualToString:@""]) {
//
//    }
//    if ([self.type isEqualToString:@""]) {
//
//    }
//    if ([self.type isEqualToString:""]) {
//
//    }
    WEAKSELF
    [WYHttpServer getClewListWithState:self.type WithPageNum:@"1" WithPageSize:@"10" SucessBlock:^(BOOL success, id response, NSString *errorMessage) {
       
        if (success) {
            NSArray *array = [WYClewModel getClewModelFromJson:response[@"result"]];
            if (array.count) {
                [weakSelf.dataArray addObject:array];
            }
            
            [weakSelf.tableView reloadData];
            
        }else{
            [weakSelf toast:errorMessage];
        }
        
    }];
    
    
    
    
    
}




-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return self.dataArray.count;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return [self.dataArray[section]count];
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    WYClueCell *cell = [tableView dequeueReusableCellWithIdentifier:@"WYClueCell" forIndexPath:indexPath];
    if (!cell) {
        cell = [[NSBundle mainBundle] loadNibNamed:@"WYClueCell" owner:nil options:nil].firstObject;
    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    
    WYClewModel *model = self.dataArray[indexPath.section][indexPath.row];
    
    [cell setModel:model];
    
    return cell;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 135;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
     NSLog(@"--------------%@-------------",self.type);
}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

-(UITableView *)tableView
{
    if (!_tableView) {
        _tableView = [[UITableView alloc]init];
        _tableView.delegate=self;
        _tableView.dataSource=self;
        CGFloat height = 64 + 44;
        if (kDevice_Is_iPhoneX) {
            height = 88 +49 ;
        }
        
        _tableView.frame = CGRectMake(0, 0, kScreenWidth, kScreenHeight-height);
    }
    
    return _tableView;
}

@end
